# -*- coding: utf-8 -*-
import requests,json,os,urllib,string,sys
reload(sys)
sys.setdefaultencoding('utf8')
ind=1
def getData(val,i):
#    res=requests.get('http://matchweb.sports.qq.com/team/rank?&callback=recommendlist&competitionId='+str(i)+'&from=sporthp')
    res=requests.get('http://team.7m.com.cn/v2/encrypt/fun/getinfo.php?id='+str(i)+'&lang=big&nc=152177851')
    res=res.content[16:len(res.content)-2]
    arr=res.split(',')
    for k in arr:
        print k

def save_img(img_url,file_name,file_path='img'):
    img_url=img_url.replace('\/','/')
    try:
        if not os.path.exists(file_path):
            print '文件夹',file_path,'不存在，重新建立'
            #os.mkdir(file_path)
            os.makedirs(file_path)
        #获得图片后缀
        file_suffix = os.path.splitext(img_url)[1]
        #拼接图片名（包含路径）
        filename = '{}{}{}{}'.format(file_path,os.sep,file_name,file_suffix)
        filename=filename.replace('.com','_com')
        if string.find(filename,'.')==-1:
            filename=filename+'.png'
        if string.find(filename,'?')!=-1:
            filename=filename[0:len(filename)-4]
#       m下载图片，并保存到文件夹中
        urllib.urlretrieve(img_url,filename=filename)
    except IOError as e:
        print '文件操作失败',e
    except Exception as e:
        print '错误 ：',e

getData('',ind)
